<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'plugin/count.php';

RegisterPlugin("ydblog","ActivePlugin_ydblog");

function ActivePlugin_ydblog() {
	Add_Filter_Plugin('Filter_Plugin_Admin_TopMenu','ydblog_AddMenu');
	//Add_Filter_Plugin('Filter_Plugin_Edit_Response','ydblog_Edit_Response');
	//Add_Filter_Plugin('Filter_Plugin_Edit_Response3','ydblog_Edit_Response2');
	Add_Filter_Plugin('Filter_Plugin_Zbp_BuildModule','ydblog_rebuild_Main');
	Add_Filter_Plugin('Filter_Plugin_Category_Edit_Response','ydblog_cate_seo');//cate自定义字段
	Add_Filter_Plugin('Filter_Plugin_Tag_Edit_Response','ydblog_tag_seo');//tag自定义字段
	
	//Add_Filter_Plugin('Filter_Plugin_Zbp_BuildModule','ydblog_page_archive_cache');
	//Add_Filter_Plugin('Filter_Plugin_Zbp_BuildModule','ydblog_page_readers_cache');
	//Add_Filter_Plugin('Filter_Plugin_Zbp_BuildModule','ydblog_page_tagss_cache');
	//Add_Filter_Plugin('Filter_Plugin_Category_Edit_Response','ydblog_category_title');
	//Add_Filter_Plugin('Filter_Plugin_Edit_Response','ydblog_Edit_Response');
	//Add_Filter_Plugin('Filter_Plugin_Edit_Response3','ydblog_jiage');//插入字段价格等
	//Add_Filter_Plugin('Filter_Plugin_Edit_Response3','ydblog_Edit_right'); 
}


function ydblog_cate_seo(){
    global $zbp,$cate;
	echo '<div id="alias" class="editmod">
       <span class="title">当前分类标题、关键词、描述<font color="#FF0000">(不填写则按主题默认显示,注：此功能为当前模板自带)</font></span><br />
       <strong>标题</strong><br>
       <input type="text" style="width:75%;" name="meta_ydblog_catetitle" value="'.htmlspecialchars($cate->Metas->ydblog_catetitle).'"/><br>
       <strong>关键词</strong><br>
       <input type="text" style="width:75%;" name="meta_ydblog_catekeywords" value="'.htmlspecialchars($cate->Metas->ydblog_catekeywords).'"/><br>
       <strong>描述</strong><br>
       <input type="text" style="width:75%;" name="meta_ydblog_catemiaoshu" value="'.htmlspecialchars($cate->Metas->ydblog_catemiaoshu).'"/>
       </div>';
}
function ydblog_tag_seo(){
    global $zbp,$tag;
	echo '<div id="alias" class="editmod">
       <span class="title">当前TAG标题、关键词、描述<font color="#FF0000">(不填写则按主题默认显示,注：此功能为当前模板自带)</font></span><br />
       <strong>标题</strong><br>
       <input type="text" style="width:75%;" name="meta_ydblog_tagtitle" value="'.htmlspecialchars($tag->Metas->ydblog_tagtitle).'"/><br>
       <strong>关键词</strong><br>
       <input type="text" style="width:75%;" name="meta_ydblog_tagkeywords" value="'.htmlspecialchars($tag->Metas->ydblog_tagkeywords).'"/><br>
       <strong>描述</strong><br>
       <input type="text" style="width:75%;" name="meta_ydblog_tagmiaoshu" value="'.htmlspecialchars($tag->Metas->ydblog_tagmiaoshu).'"/>
       </div>';
}


function ydblog_Edit_right(){
	global $zbp,$article;
	ydblog_liststyle($article);
}
function ydblog_liststyle($article){
	global $zbp;
	$array = array('ydblog_appurl'=>'淘宝链接');
	if(is_array($array)==false)return null;
	if(count($array)==0)return null;
	echo '<font color="#FF0000">没有淘宝链接可不填写</font>';
	foreach ($array as $key => $value) {
		if(!$value) $value = 'Metas.' . $key;
		
		else{
			echo '<p><label class="editinputname" for="'. $key .'" >' . $value . '</label><input type="text" name="meta_' . $key . '" value="'.htmlspecialchars($article->Metas->$key).'" style="width:171px;"/></p>';
		}
	}
}
//插入字段价格等
function ydblog_jiage(){
    global $zbp,$article;
   	echo '<div id="alias" class="editmod">

	<label for="meta_jiage" class="editinputname"><font color="#FF0000">价格</font></label>
	<input type="text" name="meta_jiage" value="'.htmlspecialchars($article->Metas->jiage).'"/>
	<label for="meta_menshijiage" class="editinputname"><font color="#FF0000">门市价</font></label>
	<input type="text" name="meta_menshijiage" value="'.htmlspecialchars($article->Metas->menshijiage).'"/>
	<label for="meta_xiaoliang" class="editinputname"><font color="#FF0000">已售</font></label>
	<input type="text" name="meta_xiaoliang" value="'.htmlspecialchars($article->Metas->xiaoliang).'"/>
	</div>';
}

//后台按钮
function ydblog_AddMenu(&$m){
	global $zbp;
	array_unshift($m, MakeTopMenu("root",'主题配置',$zbp->host . "zb_users/theme/ydblog/main.php?act=a","","topmenu_ydblog"));

}
function ydblog_SubMenu($id){
	$arySubMenu = array(
		0 => array('基本设置', 'a', 'left', false),
		1 => array('主题配色', 'm', 'left', false),
		2 => array('开关设置', 'b', 'left', false),
		3 => array('顶菜单', 'j', 'left', false),
		4 => array('左菜单', 'k', 'left', false),
		//4 => array('左下N图', 'i', 'left', false),
		//5 => array('幻灯片', 'e', 'left', false),
		//6 => array('六小图', 'f', 'left', false),
		//7 => array('首页多图', 'g', 'left', false),
		//8 => array('右下三图', 'h', 'left', false),
		//9 => array('缩略图', 'mini', 'left', false),
		//2 => array('SEO广告', 'c', 'left', false),
		
	);
	foreach($arySubMenu as $k => $v){
		echo '<a href="?act='.$v[1].'" '.($v[3]==true?'target="_blank"':'').'><span class="m-'.$v[2].' '.($id==$v[1]?'m-now':'').'">'.$v[0].'</span></a>';
	}
}
//热门模块
function ydblog_include_hot(){
	global $zbp;
	$str .='这里是热门文章   使用方法：拖拽到合适的侧边栏即可，不小心删除了进入ydblog主题配置去更新缓存';
	//return $str;
	file_put_contents($zbp->usersdir . 'theme/ydblog/include/hotpost.php', $str);
}
//随机模块
function ydblog_include_rand(){
	global $zbp;
	$str .='这里是随机文章    使用方法：拖拽到合适的侧边栏即可，不小心删除了进入ydblog主题配置去更新缓存';
	//return $str;
	file_put_contents($zbp->usersdir . 'theme/ydblog/include/randpost.php', $str);
}
//左侧栏TAGS
function ydblog_left_Tags(){
	global $zbp,$str;
	$str = '';
	$i = $zbp->modulesbyfilename['tags']->MaxLi;
	if ($i == 0) $i = 20;
	$array = $zbp->GetTagList('','',array('tag_Count'=>'DESC'),array($i),'');

	foreach ($array as $tag) {
		$str .= '<li><a href="' . $tag->Url . '" target="_blank">' . $tag->Name . '</a></li>';
	}
	return $str;
}
//侧边栏随机文章
function ydblog_module_Rand(){
    global $zbp,$str,$order;
    $str='';
    $sql = $zbp->db->sql->Select(
        $zbp->table['Post'],
        array("MIN(log_ID)","MAX(log_ID)"),
        array(
            array('=', 'log_Type', '0'),
            array('=', 'log_Status', '0'),
        ),
        array('log_PostTime' => 'ASC'),
        null,
        null
    );
    $array = $zbp->db->Query($sql);
    $i=mt_rand($array[0]["MIN(log_ID)"],$array[0]["MAX(log_ID)"]);
    $order = '';
    $where = array(
          array('=','log_Status','0'),
          array('>','log_ID',$i)
          );
    $array = $zbp->GetArticleList(array('*'),$where,$order,array(5),''); 
        foreach ($array as $article) {
		if ($zbp->CheckPlugin('IMAGE')){ IMAGE::getPics($article,80,65,4); }
		if ($zbp->CheckPlugin('sf_img1')){ SF_img1::getPics($article,80,65,4); }

		if (($zbp->CheckPlugin('IMAGE')) && ($article->IMAGE_COUNT>0)){
			$str .= '<li><a href="' . $article->Url. '" title="' . $article->Title. '" target="_blank"><img src="' .$article->IMAGE[0]. '" alt="' . $article->Title. '" class="thumbnail" /><div class="hotpost-left"><span class="hot-post-title" >' . $article->Title. '</span><span class="hot-post-info" ><i class="icon-clock"></i>' . $article->Time('Y-m-d'). '</span><span class="hot-post-info" ><i class="icon-eye"></i>' . $article->ViewNums. '</span></div></a></li>';
		}elseif (($zbp->CheckPlugin('sf_img1')) && ($article->sf_img_count>0)){
			$str .= '<li><a href="' . $article->Url. '" title="' . $article->Title. '" target="_blank"><img src="' .$article->sf_img[0]. '" alt="' . $article->Title. '" class="thumbnail" /><div class="hotpost-left"><span class="hot-post-title" >' . $article->Title. '</span><span class="hot-post-info" ><i class="icon-clock"></i>' . $article->Time('Y-m-d'). '</span><span class="hot-post-info" ><i class="icon-eye"></i>' . $article->ViewNums. '</span></div></a></li>';
		}
		else{
			$str .= '<li><a href="' . $article->Url. '" title="' . $article->Title. '" target="_blank"><img src="' .(ydblog_thumbnail($article)). '" alt="' . $article->Title. '" class="thumbnail" /><div class="hotpost-left"><span class="hot-post-title" >' . $article->Title. '</span><span class="hot-post-info" ><i class="icon-clock"></i>' . $article->Time('Y-m-d'). '</span><span class="hot-post-info" ><i class="icon-eye"></i>' . $article->ViewNums. '</span></div></a></li>';	
		}
        }
        return $str;
}
//摘要文字
function ydblog_zhai($as,$type,$long,$other) {
    global $zbp;
    $str = '';
    if ($type=='0') {
    //$str .= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($as->Intro,'[nohtml]'),$long)).$other);
	$str .= trim(SubStrUTF8(TransferHTML($as->Intro,'[nohtml]'),$long)).$other;
    } else {
    //$str .= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($as->Content,'[nohtml]'),$long)).$other);
	$str .= trim(SubStrUTF8(TransferHTML($as->Content,'[nohtml]'),$long)).$other;
    }
    return $str;
}
//无缩略图插件用
function ydblog_thumbnail($related) {
    global $zbp;	
	$temp=mt_rand(1,10);
	$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
	$content = $related->Content; 
	preg_match_all($pattern,$content,$matchContent);
	if(isset($matchContent[1][0])){
		$thumb=$matchContent[1][0];
	}else{		
		$thumb=$zbp->host . "zb_users/theme/" .$zbp->theme. "/include/random/" .$temp. ".png";
	}
    return $thumb;
}

//获取随机标签
function ydblog_Get_rdTags(){
global $zbp,$str;
$str = '';
$array = $zbp->GetTagList('','',array('rand()'=>' '),array(10),'');
foreach ($array as $tag) {
$str .= "<a href=\"{$tag->Url}\" title=\"{$tag->Name}\" target=\"_blank\">{$tag->Name}</a>  ";
}
return $str;
}
//中文月份
function ydblog_GetChineseMonth($month){
$array = array('一','二','三','四','五','六','七','八','九','十','十一','十二');
return $array[$month-1];
}


//初始安装
function InstallPlugin_ydblog(){
	global $zbp;
	if(!$zbp->Config('ydblog')->HasKey('Version')){
		$zbp->Config('ydblog')->Version = '1.0';
		$zbp->Config('ydblog')->Tjdm = '统计代码JS';
		$zbp->Config('ydblog')->indextitle = '';
		$zbp->Config('ydblog')->Contactlink ='http://www.ylefu.com/';
		$zbp->Config('ydblog')->aboutlink = '#';
		$zbp->Config('ydblog')->Gjc = '关键词1，关键词2，关键词3，关键词4';
		$zbp->Config('ydblog')->Ms = '纸品印记北京高档名片制作（纸品印记广告有限公司），拥有名片设计/印刷/工艺加工全系列生产设备，专注高档名片制作、北京名片制作、名片印刷、特种纸名片加工。';
		$zbp->Config('ydblog')->QQ = '10000';
		$zbp->Config('ydblog')->phone = '13800138000';
		$zbp->Config('ydblog')->Dizhi = '郑州市xxx区xxx号A座204室';
		$zbp->Config('ydblog')->banquan = '我的微信号：138 0000 0000 （左侧二维码扫一扫）欢迎添加！';
		$zbp->Config('ydblog')->colorone = '#174900';
		$zbp->Config('ydblog')->colortwo = '#004401';
		$zbp->Config('ydblog')->colorthree = '#b3f4b0';
		$zbp->Config('ydblog')->colorfour ='#366655';
		$zbp->Config('ydblog')->related = '1';
		$zbp->Config('ydblog')->ydblog_relatedshuzi ='4';
		$zbp->Config('ydblog')->wxkg = '1';
		$zbp->Config('ydblog')->wxkg4 = '1';
		$zbp->Config('ydblog')->indexistop = '1';
		$zbp->Config('ydblog')->navleftonoff = '1';
		$zbp->Config('ydblog')->ydblog_leftlianxiiconoff =='1';
		$zbp->Config('ydblog')->hdponoff = '1';
		$zbp->Config('ydblog')->s6tuoff = '1';
		$zbp->Config('ydblog')->loginonoff = '1';
		$zbp->Config('ydblog')->lefttagsyunoff = '1';
		$zbp->Config('ydblog')->Indexyx3off = '1';
		$zbp->Config('ydblog')->navleft = 'navleftdiy';
		$zbp->Config('ydblog')->navleftdiyhtml = '<li><a href="http://www.52fb.cn/jiage/"><i class="icon-calendar"></i> 名片价格</a></li>
<li class=" submenu"><a href="http://www.52fb.cn/zhizhang/"><i class="icon-doc-text-inv"></i> 名片纸张 <span class="sign "></span></a>
<ul class="sub-menu">
	<li><a href=""><i class="icon-doc-text-inv"></i> 专色名片纸张</a></li>
	<li><a href=""><i class="icon-right-dir"></i> 专色: 珠光炫彩</a></li>
	</ul>
</li>
<li class=" submenu"><a href="http://www.52fb.cn/gongyi/"><i class="icon-check"></i> 名片工艺 <span class="sign "></span></a>
<ul class="sub-menu">
	<li><a href=""><i class="icon-check"></i> 烫金烫银(多色)</a></li>
	</ul>
</li>
<li><a href="http://www.52fb.cn/day/"><i class="icon-camera"></i> 每天一图</a></li>';
		$zbp->Config('ydblog')->huandengpianoff1 = '1';
		$zbp->Config('ydblog')->stitlea = '幻灯片1标题';
		$zbp->Config('ydblog')->slinka = '#';
		$zbp->Config('ydblog')->huandengpianoff2 = '1';
		$zbp->Config('ydblog')->stitleb = '幻灯片2标题';
		$zbp->Config('ydblog')->slinkb = '#';
		$zbp->Config('ydblog')->stitleaa = '烫金烫银';
		$zbp->Config('ydblog')->stitlebb = '凹凸浮雕';
		$zbp->Config('ydblog')->stitlecc = '异形镂空';
		$zbp->Config('ydblog')->stitledd = '圆角名片';
		$zbp->Config('ydblog')->stitleee = '凸版压凹';
		$zbp->Config('ydblog')->stitleff = '水晶UV';
		$zbp->Config('ydblog')->Listoff1 = '1';
		$zbp->Config('ydblog')->List1 = '1';
		$zbp->Config('ydblog')->Tushu1 = '6';
		$zbp->Config('ydblog')->Listoff2 = '1';
		$zbp->Config('ydblog')->List2 = '2';
		$zbp->Config('ydblog')->Tushu2 = '3';
		$zbp->Config('ydblog')->Indexyx3title = '快捷导航';
		$zbp->Config('ydblog')->stitleaaa = '名片纸张';
		$zbp->Config('ydblog')->stitlebbb = '名片工艺';
		$zbp->Config('ydblog')->stitleccc = '名片价格';
		$zbp->Config('ydblog')->navtopoff1 = '1';
		$zbp->Config('ydblog')->navtoptitlea = '凸版印刷';
		$zbp->Config('ydblog')->navtoplinka = 'http://www.b5b6.com/';
		$zbp->Config('ydblog')->navtopicon1 = '<i class="icon-check"></i>';
		$zbp->Config('ydblog')->navtopoff2 = '1';
		$zbp->Config('ydblog')->navtoptitleb = '这里设置';
		$zbp->Config('ydblog')->navtoplinkb = 'zb_users/theme/ydblog/main.php?act=j';
		$zbp->Config('ydblog')->navtopicon2 = '<i class="icon-calendar"></i>';
		$zbp->Config('ydblog')->navtopicon3 = '<i class="icon-doc-text-inv"></i>';
		$zbp->Config('ydblog')->navtopicon4 = '<i class="icon-check"></i>';
		$zbp->Config('ydblog')->navtopicon5 = '<i class="icon-camera"></i>';
		$zbp->Config('ydblog')->navtopicon6 = '<i class="icon-location"></i>';
		$zbp->Config('ydblog')->navtopicon7 = '<i class="icon-user"></i>';
		$zbp->Config('ydblog')->navtopoff7 = '1';
		$zbp->Config('ydblog')->navtoptitleg = '导航名字';
		$zbp->Config('ydblog')->navtoplinkg = '#';
		$zbp->Config('ydblog')->navtopxialaoff1 = '1';
		$zbp->Config('ydblog')->navtopxialaicon1 = '<i class="icon-arrows-cw"></i>';
		$zbp->Config('ydblog')->navtopxialatitle1 = '标题1';
		$zbp->Config('ydblog')->navtopxialalink1 = '#';
		$zbp->Config('ydblog')->ydblog_leftimg ='1,2,3';//左列图ID
		$zbp->Config('ydblog')->ydblog_leftimgtitle ='推荐图片';//左列图
		$zbp->Config('ydblog')->ydblog_leftimgoff ='1';//左列图
		$zbp->Config('ydblog')->ydblog_searchoff ='1';//搜索
		$zbp->Config('ydblog')->ydblog_clearSetting ='0';//清配置
		$zbp->Config('ydblog')->ydblog_gonggao ='1,2,3';//公告
		$zbp->Config('ydblog')->ydblog_gonggaooff ='1';
		$zbp->Config('ydblog')->ydblog_biglist ='1';
		$zbp->SaveConfig('ydblog');
	}
}

//卸载主题
function UninstallPlugin_ydblog(){
	global $zbp;
	//清空主题配置
	if ($zbp->Config('ydblog')->ydblog_clearSetting){
		$zbp->DelConfig('ydblog');
	}
	//
	$zbp->SetHint('good','OK'); //原来这句是保存后返回原设置界面。
}

?>